#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#define num 10
void swap(int* q, int* a)
{
	int tem = *q;
	*q = *a;
	*a = tem;
}
void select_sort(int* a, int n)
{
	int begin = 0, end = n - 1;
	while (begin < end)
	{	
		int min = begin, max = begin;
		for (int i = min; i < end; i++)
		{
			if (a[i] < a[min])
				min = i;
			if (a[i] > a[max])
				max = i;
		}
		swap(&a[min], &a[begin]);
		if (begin == max)
			max = min;
		swap(&a[max], &a[end]);
		begin++; end--;
	}
}
void AdjustDown(int* a, int n, int parent)
{
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (child + 1 < n && a[child + 1] > a[child])
		{
			child++;
		}
			
		if (a[child] > a[parent])
		{
			swap(&a[child], &a[parent]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
			break;
	}
}
void HeapSort(int* a, int n)
{
	for (int i = (n - 1 - 1) / 2; i >= 0; i--)
	{
		AdjustDown(a, n, i);
	}
	int end = n - 1;
	while (end > 0)
	{
		swap(&a[0], &a[end]);
		AdjustDown(a, end, 0);
		--end;
	}
}
int main()
{
	int arr[num] = { 3,1,4,5,2,7,9,0,8,6 };
	select_sort(arr, num);
	//HeapSort(arr, num);
	for (int i = 0; i < num; i++)
	{
		printf("%d ", arr[i]);
	}
}